<!DOCTYPE html>
<html lang="en">
    <head>

        <meta charset="UTF-8">

        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">


    </head>
    <body>
    <form >
        id     <input  id="username" type="text" name="username"><br>
        passwd <input  id="passwd" type="password" name="password"><br>
        <input type="submit" value="提交" name="submit ">

    </form>
    <button onclick="test()">简单的按钮</button>
    </body>

    <script>
         let websocket = new WebSocket("ws://43.140.252.84:8888");
                websocket.onopen = function() {
                alert("连接建⽴");
                }
                // 处理收到消息的回调函数
                // 控制台打印消息
                websocket.onmessage = function(e) {
                alert("收到消息: " + e.data);
                }
                // 处理连接异常的回调函数
                websocket.onerror = function() {
                alert("连接异常");
                }
                // 处理连接关闭的回调函数
                websocket.onclose = function() {
                alert("连接关闭");
                }
            function test()
            {
                websocket.send(document.getElementById("username").value);


            }
        </script>
</html>